package com.putao.album.util;

import android.graphics.drawable.BitmapDrawable;

import com.putao.album.application.GlobalApplication;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by jidongdong on 15/5/13.
 */
public class ResourcesHelper {
    /**
     * 读取Asset文本资源内容
     *
     * @param resName
     * @return
     */
    public static String getAssetTextFile(String resName) {
        String protocal = null;
        try {
            InputStreamReader reader = new InputStreamReader(GlobalApplication.getInstance().getResources().getAssets().open(resName));
            BufferedReader br = new BufferedReader(reader);
            String line = "";
            String Result = "";
            while ((line = br.readLine()) != null)
                Result += line;
            return Result;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return protocal;
    }

    /**
     * 获取图片资源的BitmapDrawable
     *
     * @param resId
     * @return
     */
    public static BitmapDrawable getBitmapDrawable(int resId) {
        return (BitmapDrawable) GlobalApplication.getInstance().getResources().getDrawable(resId);
    }
}
